package homework.gademo;

import homework.gademo.interceptor.LoginHandlerInterceptor;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

@Configuration
public class WebConfiguration extends WebMvcConfigurationSupport {

	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {

		registry.addResourceHandler("/images/**").addResourceLocations(
				"classpath:/static/images/");
		registry.addResourceHandler("/js/**").addResourceLocations(
				"classpath:/static/js/");
		registry.addResourceHandler("/css/**").addResourceLocations(
				"classpath:/static/layui/css/");
		super.addResourceHandlers(registry);
	}

	@Bean
	public LoginHandlerInterceptor getSecurityInterceptor() {
		return new LoginHandlerInterceptor();
	}

	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		InterceptorRegistration addInterceptor = registry
				.addInterceptor(getSecurityInterceptor());

		addInterceptor.excludePathPatterns("/register**", "/", "/error",
				"/user/login", "/user/logout", "/user/register", "/static/**",
				"/js/**", "/css/**");
		// 拦截配置
		addInterceptor.addPathPatterns("/**");
	}
}